package com.ueboot.weishop.repository.customer;

import com.ueboot.weishop.entity.customer.CustomerInvoiceEntity;
import com.ueboot.core.repository.BaseRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Created by Neel on 2017/9/18.
 */
@Repository
public interface CustomerInvoiceRepository extends BaseRepository<CustomerInvoiceEntity, Long> {

	/**
	 * 根据用户ID查询发票信息
	 *
	 * @param customerId 用户Id
	 * @return
	 */
	List<CustomerInvoiceEntity> findByCustomerId(Long customerId);

	@Modifying
	@Query("UPDATE #{#entityName} oe set oe.defaultInvoice = :unDefault where customer.id = :customerId")
	void updateUnDefaultByCustomerId(@Param("customerId") Long customerId, @Param("unDefault") Boolean unDefault);

	CustomerInvoiceEntity findById(Long invoiceId);
}
